﻿#Region "Copyright"
'————————————————————————————————————————
'	创建人员(Creator)    ：Huangyd
'	创建日期(Date)       ：2012-07-14
'   联系方式(Email)      ：aj-ayumi@163.com; gajayumi@gmail.com; ajayumi@me.com
'   描    述(Description)：
'
'	Copyright (C) 2012 ajayumi 版权所有
'————————————————————————————————————————
#End Region
Imports System.Runtime.InteropServices
Imports System.Drawing

Namespace WinAPI

    ''' <summary> 
    ''' Define the window messages 
    ''' </summary> 
    Public Module WindowsMessage
        Sub New()
        End Sub
        Public Const WM_LBUTTONDOWN As Int32 = &H201
        Public Const WM_NCLBUTTONDOWN As Int32 = &HA1
        Public Const WM_SYSCOMMAND As Int32 = &H112
        Public Const WM_PAINT As Int32 = &HF
        Public Const WM_MOVE As Int32 = &H3
        Public Const WM_CTLCOLORMSGBOX As Int32 = &H132
        Public Const WM_CTLCOLOREDIT As Int32 = &H133
        Public Const WM_CTLCOLORLISTBOX As Int32 = &H134
        Public Const WM_CTLCOLORBTN As Int32 = &H135
        Public Const WM_CTLCOLORDLG As Int32 = &H136
        Public Const WM_CTLCOLORSCROLLBAR As Int32 = &H137
        Public Const WM_CTLCOLORSTATIC As Int32 = &H138
        Public Const WM_CAPTURECHANGED As Int32 = &H215
    End Module

    ''' <summary> 
    ''' Define the window class types 
    ''' </summary> 
    Public Module WndClassType
        Sub New()
        End Sub
        Public Const CS_VREDRAW As Int32 = &H1
        Public Const CS_HREDRAW As Int32 = &H2
        Public Const CS_DBLCLKS As Int32 = &H8
        Public Const CS_OWNDC As Int32 = &H20
        Public Const CS_CLASSDC As Int32 = &H40
        Public Const CS_PARENTDC As Int32 = &H80
        Public Const CS_NOCLOSE As Int32 = &H200
        Public Const CS_SAVEBITS As Int32 = &H800
        Public Const CS_BYTEALIGNCLIENT As Int32 = &H1000
        Public Const CS_BYTEALIGNWINDOW As Int32 = &H2000
        Public Const CS_GLOBALCLASS As Int32 = &H4000
        Public Const CS_IME As Int32 = &H10000
        Public Const CS_DROPSHADOW As Int32 = &H20000
    End Module

    ''' <summary> 
    ''' Window style 
    ''' </summary> 
    Public Module WndStyle
        Sub New()
        End Sub
        Public Const WS_OVERLAPPED As UInt32 = &H0
        Public Const WS_POPUP As Integer = &H80000000
        Public Const WS_CHILD As UInt32 = &H40000000
        Public Const WS_MINIMIZE As UInt32 = &H20000000
        Public Const WS_VISIBLE As UInt32 = &H10000000
        Public Const WS_DISABLED As UInt32 = &H8000000
        Public Const WS_CLIPSIBLINGS As UInt32 = &H4000000
        Public Const WS_CLIPCHILDREN As UInt32 = &H2000000
        Public Const WS_MAXIMIZE As UInt32 = &H1000000
        Public Const WS_CAPTION As UInt32 = &HC00000
        Public Const WS_BORDER As UInt32 = &H800000
        Public Const WS_DLGFRAME As UInt32 = &H400000
        Public Const WS_VSCROLL As UInt32 = &H200000
        Public Const WS_HSCROLL As UInt32 = &H100000
        Public Const WS_SYSMENU As UInt32 = &H80000
        Public Const WS_THICKFRAME As UInt32 = &H40000
        Public Const WS_GROUP As UInt32 = &H20000
        Public Const WS_TABSTOP As UInt32 = &H10000
        Public Const WS_MINIMIZEBOX As UInt32 = &H20000
        Public Const WS_MAXIMIZEBOX As UInt32 = &H10000
        Public Const WS_TILED As UInt32 = WS_OVERLAPPED
        Public Const WS_ICONIC As UInt32 = WS_MINIMIZE
        Public Const WS_SIZEBOX As UInt32 = WS_THICKFRAME
        Public Const WS_TILEDWINDOW As UInt32 = WS_OVERLAPPEDWINDOW
        Public Const WS_OVERLAPPEDWINDOW As UInt32 = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
        Public Const WS_POPUPWINDOW As Integer = (WS_POPUP Or WS_BORDER Or WS_SYSMENU)
        Public Const WS_CHILDWINDOW As UInt32 = (WS_CHILD)

    End Module

    ''' <summary> 
    ''' Extended Window Styles 
    ''' </summary> 
    Public Module ExtendedWndStyle
        Sub New()
        End Sub
        Public Const WS_EX_DLGMODALFRAME As UInt32 = &H1
        Public Const WS_EX_NOPARENTNOTIFY As UInt32 = &H4
        Public Const WS_EX_TOPMOST As UInt32 = &H8
        Public Const WS_EX_ACCEPTFILES As UInt32 = &H10
        Public Const WS_EX_TRANSPARENT As UInt32 = &H20
        Public Const WS_EX_MDICHILD As UInt32 = &H40
        Public Const WS_EX_TOOLWINDOW As UInt32 = &H80
        Public Const WS_EX_WINDOWEDGE As UInt32 = &H100
        Public Const WS_EX_CLIENTEDGE As UInt32 = &H200
        Public Const WS_EX_CONTEXTHELP As UInt32 = &H400
        Public Const WS_EX_RIGHT As UInt32 = &H1000
        Public Const WS_EX_LEFT As UInt32 = &H0
        Public Const WS_EX_RTLREADING As UInt32 = &H2000
        Public Const WS_EX_LTRREADING As UInt32 = &H0
        Public Const WS_EX_LEFTSCROLLBAR As UInt32 = &H4000
        Public Const WS_EX_RIGHTSCROLLBAR As UInt32 = &H0
        Public Const WS_EX_CONTROLPARENT As UInt32 = &H10000
        Public Const WS_EX_STATICEDGE As UInt32 = &H20000
        Public Const WS_EX_APPWINDOW As UInt32 = &H40000
        Public Const WS_EX_OVERLAPPEDWINDOW As UInt32 = (WS_EX_WINDOWEDGE Or WS_EX_CLIENTEDGE)
        Public Const WS_EX_PALETTEWINDOW As UInt32 = (WS_EX_WINDOWEDGE Or WS_EX_TOOLWINDOW Or WS_EX_TOPMOST)
        Public Const WS_EX_LAYERED As UInt32 = &H80000
        Public Const WS_EX_NOINHERITLAYOUT As UInt32 = &H100000
        Public Const WS_EX_LAYOUTRTL As UInt32 = &H400000
        Public Const WS_EX_COMPOSITED As UInt32 = &H2000000
        Public Const WS_EX_NOACTIVATE As UInt32 = &H8000000
    End Module

    ''' <summary> 
    ''' WNDPROC 
    ''' </summary> 
    ''' <param name="hWnd"></param> 
    ''' <param name="msg"></param> 
    ''' <param name="wParam"></param> 
    ''' <param name="lParam"></param> 
    ''' <returns></returns> 
    Public Delegate Function WndProcDelegate(ByVal hWnd As IntPtr, ByVal msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

    ''' <summary> 
    ''' WNDCLASSEX 
    ''' </summary> 
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
    Public Structure WNDCLASSEX
        <MarshalAs(UnmanagedType.U4)> _
        Public cbSize As UInteger
        <MarshalAs(UnmanagedType.U4)> _
        Public style As UInteger
        Public lpfnWndProc As WndProcDelegate
        Public cbClsExtra As Integer
        Public cbWndExtra As Integer
        Public hInstance As IntPtr
        Public hIcon As IntPtr
        Public hCursor As IntPtr
        Public hbrBackground As IntPtr
        <MarshalAs(UnmanagedType.LPWStr)> _
        Public lpszMenuName As String
        <MarshalAs(UnmanagedType.LPWStr)> _
        Public lpszClassName As String
        Public hIconSm As IntPtr

        Public Sub Init()
            cbSize = CUInt(Marshal.SizeOf(Me))
        End Sub
    End Structure

    Public Enum MousePositionCodes As Integer
        HTERROR = -2
        HTTRANSPARENT = -1
        HTNOWHERE = 0
        HTCLIENT = 1
        HTCAPTION = 2
        HTSYSMENU = 3
        HTGROWBOX = 4
        HTSIZE = HTGROWBOX
        HTMENU = 5
        HTHSCROLL = 6
        HTVSCROLL = 7
        HTMINBUTTON = 8
        HTMAXBUTTON = 9
        HTLEFT = 10
        HTRIGHT = 11
        HTTOP = 12
        HTTOPLEFT = 13
        HTTOPRIGHT = 14
        HTBOTTOM = 15
        HTBOTTOMLEFT = 16
        HTBOTTOMRIGHT = 17
        HTBORDER = 18
        HTOBJECT = 19
        HTCLOSE = 20
        HTHELP = 21
    End Enum

    Public Module BlendOp
        Sub New()
        End Sub
        Public Const AC_SRC_OVER As Byte = &H0
        Public Const AC_SRC_ALPHA As Byte = &H1
    End Module


    ''' <summary> 
    ''' BLENDFUNCTION 
    ''' </summary> 
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure BLENDFUNCTION
        Private BlendOp As Byte
        Private BlendFlags As Byte
        Private SourceConstantAlpha As Byte
        Private AlphaFormat As Byte

        Public Sub New(ByVal op As Byte, ByVal flags As Byte, ByVal alpha As Byte, ByVal format As Byte)
            BlendOp = op
            BlendFlags = flags
            SourceConstantAlpha = alpha
            AlphaFormat = format
        End Sub
    End Structure

    ''' <summary> 
    ''' Point extend 
    ''' </summary> 
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure PointEx
        Public X As Integer
        Public Y As Integer

        Public Sub New(ByVal x As Integer, ByVal y As Integer)
            Me.X = x
            Me.Y = y
        End Sub

        Public Shared Widening Operator CType(ByVal p As PointEx) As Point
            Return New Point(p.X, p.Y)
        End Operator

        Public Shared Widening Operator CType(ByVal p As Point) As PointEx
            Return New PointEx(p.X, p.Y)
        End Operator
    End Structure

    <Serializable(), StructLayout(LayoutKind.Sequential)> _
    Public Structure RectangleEx
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer

        Public Sub New(ByVal left_ As Integer, ByVal top_ As Integer, ByVal right_ As Integer, ByVal bottom_ As Integer)
            Left = left_
            Top = top_
            Right = right_
            Bottom = bottom_
        End Sub

        Public ReadOnly Property Height() As Integer
            Get
                Return Bottom - Top
            End Get
        End Property
        Public ReadOnly Property Width() As Integer
            Get
                Return Right - Left
            End Get
        End Property
        Public ReadOnly Property Size() As SizeEx
            Get
                Return New SizeEx(Width, Height)
            End Get
        End Property

        Public ReadOnly Property Location() As Point
            Get
                Return New Point(Left, Top)
            End Get
        End Property

        Public Function ToRectangle() As Rectangle
            Return Rectangle.FromLTRB(Left, Top, Right, Bottom)
        End Function

        Public Shared Function FromRectangle(ByVal rectangle As Rectangle) As RectangleEx
            Return New RectangleEx(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom)
        End Function

        Public Overloads Overrides Function GetHashCode() As Integer
            Return Left Xor ((Top << 13) Or (Top >> &H13)) Xor ((Width << &H1A) Or (Width >> 6)) Xor ((Height << 7) Or (Height >> &H19))
        End Function

#Region "Operator overloads"

        Public Shared Widening Operator CType(ByVal rect As RectangleEx) As Rectangle
            Return rect.ToRectangle()
        End Operator

        Public Shared Widening Operator CType(ByVal rect As Rectangle) As RectangleEx
            Return FromRectangle(rect)
        End Operator

#End Region

    End Structure


    ''' <summary> 
    ''' Size extend
    ''' </summary> 
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure SizeEx
        Public cx As Integer
        Public cy As Integer

        Public Sub New(ByVal cx As Integer, ByVal cy As Integer)
            Me.cx = cx
            Me.cy = cy
        End Sub
    End Structure

    Public Module CompressionType
        Sub New()
        End Sub
        Public Const BI_RGB As Byte = 0
        Public Const BI_RLE8 As Byte = 1
        Public Const BI_RLE4 As Byte = 2
        Public Const BI_BITFIELDS As Byte = 3
        Public Const BI_JPEG As Byte = 4
        Public Const BI_PNG As Byte = 5
    End Module

    Public Module DIBColorTableIdentifier
        Sub New()
        End Sub
        Public Const DIB_RGB_COLORS As Byte = 0
        Public Const DIB_PAL_COLORS As Byte = 1
    End Module

    Public Module UpdateLayerWindowParameter
        Sub New()
        End Sub
        Public Const ULW_COLORKEY As Integer = &H1
        Public Const ULW_ALPHA As Integer = &H2
        Public Const ULW_OPAQUE As Integer = &H4
        Public Const ULW_EX_NORESIZE As Integer = &H8
    End Module


    Public Module WindowsLong
        Sub New()
        End Sub
        Public Const GWL_WNDPROC As Integer = -4
        Public Const GWL_HINSTANCE As Integer = -6
        Public Const GWL_HWNDPARENT As Integer = -8
        Public Const GWL_STYLE As Integer = -16
        Public Const GWL_EXSTYLE As Integer = -20
        Public Const GWL_USERDATA As Integer = -21
        Public Const GWL_ID As Integer = -12
    End Module

    <Serializable(), StructLayout(LayoutKind.Sequential)> _
    Public Structure GUITHREADINFO
        Public cbSize As UInteger
        Public flags As UInteger
        Public hwndActive As IntPtr
        Public hwndFocus As IntPtr
        Public hwndCapture As IntPtr
        Public hwndMenuOwner As IntPtr
        Public hwndMoveSize As IntPtr
        Public hwndCaret As IntPtr
        Public rcCaret As RectangleEx

        Public Sub Init()
            cbSize = CUInt(Marshal.SizeOf(Me))
        End Sub
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure BITMAPINFOHEADER
        Public biSize As UInteger
        Public biWidth As Integer
        Public biHeight As Integer
        Public biPlanes As UShort
        Public biBitCount As UShort
        Public biCompression As UInteger
        Public biSizeImage As UInteger
        Public biXPelsPerMeter As Integer
        Public biYPelsPerMeter As Integer
        Public biClrUsed As UInteger
        Public biClrImportant As UInteger

        Public Sub Init()
            biSize = CUInt(Marshal.SizeOf(Me))
        End Sub
    End Structure


    ''' <summary>Enumeration of the different ways of showing a window using 
    ''' ShowWindow</summary> 
    Public Enum WindowShowStyle As UInteger
        ''' <summary>Hides the window and activates another window.</summary> 
        ''' <remarks>See SW_HIDE</remarks> 
        Hide = 0
        ''' <summary>Activates and displays a window. If the window is minimized 
        ''' or maximized, the system restores it to its original size and 
        ''' position. An application should specify this flag when displaying 
        ''' the window for the first time.</summary> 
        ''' <remarks>See SW_SHOWNORMAL</remarks> 
        ShowNormal = 1
        ''' <summary>Activates the window and displays it as a minimized window.</summary> 
        ''' <remarks>See SW_SHOWMINIMIZED</remarks> 
        ShowMinimized = 2
        ''' <summary>Activates the window and displays it as a maximized window.</summary> 
        ''' <remarks>See SW_SHOWMAXIMIZED</remarks> 
        ShowMaximized = 3
        ''' <summary>Maximizes the specified window.</summary> 
        ''' <remarks>See SW_MAXIMIZE</remarks> 
        Maximize = 3
        ''' <summary>Displays a window in its most recent size and position. 
        ''' This value is similar to "ShowNormal", except the window is not 
        ''' actived.</summary> 
        ''' <remarks>See SW_SHOWNOACTIVATE</remarks> 
        ShowNormalNoActivate = 4
        ''' <summary>Activates the window and displays it in its current size 
        ''' and position.</summary> 
        ''' <remarks>See SW_SHOW</remarks> 
        Show = 5
        ''' <summary>Minimizes the specified window and activates the next 
        ''' top-level window in the Z order.</summary> 
        ''' <remarks>See SW_MINIMIZE</remarks> 
        Minimize = 6
        ''' <summary>Displays the window as a minimized window. This value is 
        ''' similar to "ShowMinimized", except the window is not activated.</summary> 
        ''' <remarks>See SW_SHOWMINNOACTIVE</remarks> 
        ShowMinNoActivate = 7
        ''' <summary>Displays the window in its current size and position. This 
        ''' value is similar to "Show", except the window is not activated.</summary> 
        ''' <remarks>See SW_SHOWNA</remarks> 
        ShowNoActivate = 8
        ''' <summary>Activates and displays the window. If the window is 
        ''' minimized or maximized, the system restores it to its original size 
        ''' and position. An application should specify this flag when restoring 
        ''' a minimized window.</summary> 
        ''' <remarks>See SW_RESTORE</remarks> 
        Restore = 9
        ''' <summary>Sets the show state based on the SW_ value specified in the 
        ''' STARTUPINFO structure passed to the CreateProcess function by the 
        ''' program that started the application.</summary> 
        ''' <remarks>See SW_SHOWDEFAULT</remarks> 
        ShowDefault = 10
        ''' <summary>Windows 2000/XP: Minimizes a window, even if the thread 
        ''' that owns the window is hung. This flag should only be used when 
        ''' minimizing windows from a different thread.</summary> 
        ''' <remarks>See SW_FORCEMINIMIZE</remarks> 
        ForceMinimized = 11
    End Enum

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure SHFileInfo
        Public Sub New(ByVal b As Boolean)
            hIcon = IntPtr.Zero
            iIcon = 0
            dwAttribs = 0
            pszDisplayName = String.Empty
            pszTypeName = String.Empty
        End Sub
        Public hIcon As IntPtr
        Public iIcon As Integer
        Public dwAttribs As UInteger
        <MarshalAs(UnmanagedType.LPStr, sizeconst:=260)> _
        Public pszDisplayName As String
        <MarshalAs(UnmanagedType.LPStr, sizeconst:=80)> _
        Public pszTypeName As String
    End Structure

    Public Enum FileInfoFlags
        SHGFI_ICON = &H100 '  //  get icon
        SHGFI_DISPLAYNAME = &H200 '  //  get display name
        SHGFI_TYPENAME = &H400 ' //  get type name
        SHGFI_ATTRIBUTES = &H800 ' //  get attributes
        SHGFI_ICONLOCATION = &H1000 ' //  get icon location
        SHGFI_EXETYPE = &H2000 ' //  return exe type
        SHGFI_SYSICONINDEX = &H4000 ' //  get system icon index
        SHGFI_LINKOVERLAY = &H8000 ' //  put a link overlay on icon  [Page]
        SHGFI_SELECTED = &H10000 ' //  show icon in selected state
        SHGFI_ATTR_SPECIFIED = &H20000 ' //  get only specified attributes
        SHGFI_LARGEICON = &H0 ' //  get large icon
        SHGFI_SMALLICON = &H1 ' //  get small icon
        SHGFI_OPENICON = &H2 ' //  get open icon
        SHGFI_SHELLICONSIZE = &H4 ' //  get shell size icon
        SHGFI_PIDL = &H8 ' //  pszPath is a pidl
        SHGFI_USEFILEATTRIBUTES = &H10 ' //  use passed dwFileAttribute
        SHGFI_ADDOVERLAYS = &H20 ' //  apply the appropriate overlays
        SHGFI_OVERLAYINDEX = &H40  '//  Get the index of the overlay
    End Enum

    ''' <summary>
    ''' 组合键枚举
    ''' </summary>
    Public Enum KeyModifiers
        None = 0
        Alt = 1
        Control = 2
        Shift = 4
        Windows = 8
    End Enum

End Namespace